package com.xbongbong.saas.script.tempenum;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FormulaPoJo;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ContractProduceEnum;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.NumberTypeEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.OrderEnum;
import com.xbongbong.saas.enums.dictionary.AllOutBoundEnum;
import com.xbongbong.saas.enums.dictionary.ArchivedEnum;
import com.xbongbong.saas.enums.dictionary.ExpressStatusEnum;
import com.xbongbong.saas.enums.dictionary.HasRedEnum;
import com.xbongbong.saas.enums.dictionary.IfStatisticEnum;
import com.xbongbong.saas.enums.dictionary.IsRedEnum;
import com.xbongbong.saas.enums.dictionary.OrderExpressStatusEnum;
import com.xbongbong.saas.enums.dictionary.OrderPayMentStatusEnum;
import com.xbongbong.saas.enums.dictionary.OrderStatusEnum;
import com.xbongbong.saas.enums.dictionary.OrderTypeEnum;
import com.xbongbong.saas.enums.dictionary.PayMethodEnum;
import com.xbongbong.saas.enums.dictionary.ShipStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author wujian
 * @version v1.0
 * @date 2020/12/22 22:00
 * @since v1.0
 */
@Getter
public enum TempContractDistributorEnum {
    // 订货单
    BASE_INFO(OrderEnum.BASE_INFO),
    ORDER_NO(OrderEnum.ORDER_NO),
    LINK_DISTRIBUTOR(OrderEnum.LINK_DISTRIBUTOR),
    STATUS(OrderEnum.STATUS),
    SIGN_PERSON(OrderEnum.SIGN_PERSON),
//    LINK_CONTACT(OrderEnum.LINK_CONTACT),

    SIGN_TIME(OrderEnum.SIGN_TIME),
    DEADLINE(OrderEnum.DEADLINE),

    OWNER_ID(OrderEnum.OWNER_ID),
    MINOR_USER(OrderEnum.MINOR_USER),

    //订货信息
    SALE_INFO(OrderEnum.SALE_INFO),
    PRODUCT(OrderEnum.PRODUCT),
    PRODUCT_TOTAL(OrderEnum.PRODUCT_TOTAL),

    //优惠券
//    COUPON(OrderEnum.COUPON),
    DISCOUNT_AMOUNT(OrderEnum.DISCOUNT_AMOUNT),
    AMOUNT(OrderEnum.AMOUNT),
    ORDER_COST(OrderEnum.ORDER_COST),
    GROSS_PROFIT(OrderEnum.GROSS_PROFIT),
    GROSS_PROFIT_RATE(OrderEnum.GROSS_PROFIT_RATE),
    CASH_PROFIT(OrderEnum.CASH_PROFIT),
    CASH_PROFIT_RATE(OrderEnum.CASH_PROFIT_RATE),

    ASSOCIATED_INFO(OrderEnum.ASSOCIATED_INFO),
    ADD_WRITE_OFF_PREPAYMENT(OrderEnum.ADD_WRITE_OFF_PREPAYMENT),
    ADD_PAYMENT_SHEET(OrderEnum.ADD_PAYMENT_SHEET),

    ADD_PAYMENT(OrderEnum.ADD_PAYMENT),

    //发货信息
    SHIP_INFO(OrderEnum.SHIP_INFO),
    LINK_PARTNER_RECEIVER(OrderEnum.LINK_PARTNER_RECEIVER),
    LINK_CONTACT_NUMBER(OrderEnum.LINK_CONTACT_NUMBER),
    SHIPPING_ADDRESS(OrderEnum.SHIPPING_ADDRESS),

    //拓展信息
    EXTEND_INFO(OrderEnum.EXTEND_INFO),
    SHIP_STSTUS(OrderEnum.SHIP_STATUS),
    RECEIVE_PAYMENT_STATUS(OrderEnum.RECEIVE_PAYMENT_STATUS),
    EXPRESS_STATUS(OrderEnum.EXPRESS_STATUS),
    TYPE(OrderEnum.TYPE),
    MEMO(OrderEnum.MEMO),
//    PAY_METHOD(OrderEnum.PAY_METHOD),

    //系统信息
    SYSTEM_INFO(OrderEnum.SYSTEM_INFO),
    ORDERER_ID(OrderEnum.ORDERER_ID),
    ORDERER(OrderEnum.ORDERER),
    CREATOR_ID(OrderEnum.CREATOR_ID),
    ADD_TIME(OrderEnum.ADD_TIME),
    UPDATE_TIME(OrderEnum.UPDATE_TIME),
    // 须在列表页展示，不在新建和表单设计展示
    FINISH_AMOUNT(OrderEnum.FINISH_AMOUNT),
    UN_FINISH_AMOUNT(OrderEnum.UN_FINISH_AMOUNT),
    BAD_AMOUNT(OrderEnum.BAD_AMOUNT),
    PAY_PERCENT(OrderEnum.PAY_PERCENT),
    INVOICE_AMOUNT(OrderEnum.INVOICE_AMOUNT),
    UN_INVOICE_AMOUNT(OrderEnum.UN_INVOICE_AMOUNT),
    // 逻辑字段
    IF_STATISTIC(OrderEnum.IF_STATISTIC),
    CURRENCY(OrderEnum.CURRENCY),
    EXCHANGE_RATE(OrderEnum.EXCHANGE_RATE),
    INSTOCK_ID(OrderEnum.INSTOCK_ID),
    OUTSTOCK_ID(OrderEnum.OUTSTOCK_ID),
    PURCHASE_ID(OrderEnum.PURCHASE_ID),
    ALL_OUT_BOUND(OrderEnum.ALL_OUT_BOUND),
    IS_RED(OrderEnum.IS_RED),
    HAS_RED(OrderEnum.HAS_RED),
    ESTIMATE_COST(OrderEnum.ESTIMATE_COST),
    REAL_COST(OrderEnum.REAL_COST),
    SHOW_PRODUCE(OrderEnum.SHOW_PRODUCE),
    LINK_CUSTOMER_HIDE(OrderEnum.LINK_CUSTOMER_HIDE),
    LINK_PARTNER_RECEIVER_HIDE(OrderEnum.LINK_PARTNER_RECEIVER_HIDE),
//    LINK_CONTACT_HIDE(OrderEnum.LINK_CONTACT_HIDE),
//    LINK_OPPORTUNITY_HIDE(OrderEnum.LINK_OPPORTUNITY_HIDE),
//     LINK_PARTNER_DISTRIBUTOR_HIDE(OrderEnum.LINK_PARTNER_DISTRIBUTOR_HIDE),
    ARCHIVED(OrderEnum.ARCHIVED),
    SIGN_NAME(OrderEnum.SIGN_NAME),
    COUPON_ID(OrderEnum.COUPON_ID),


//    QUOTATION_ID(OrderEnum.QUOTATION_ID),
//    QUOTATION_NAME(OrderEnum.QUOTATION_NAME),
//    DISCOUNT(OrderEnum.DISCOUNT),

    RECEIVABLE_PERIOD(OrderEnum.RECEIVABLE_PERIOD),
    OUTSTOCK_DISCOUNT_AMOUNT(OrderEnum.OUTSTOCK_DISCOUNT_AMOUNT),
    ;
    /**
     * 合同枚举
     */
    private OrderEnum anEnum;

    TempContractDistributorEnum(OrderEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempContractDistributorEnum> getAllEnum() {
        List<TempContractDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initOrderNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CONTRACT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CONTRACT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(ORDER_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.ORDER_NO));
        fieldAttrEntity.setIsForbidden(0);
        // 订单号强制开启严控模式
        fieldAttrEntity.setStrictController(1);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initLinkDistributor(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(LINK_CUSTOMER_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }
    public static void initLinkPartnerReceiver(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(LINK_PARTNER_RECEIVER_HIDE.getAnEnum().getAttr());
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
    }

    /**
     * 整单折扣默认为百分比，所以默认值为1（新建编辑时候就会默认展示为100%）
     * @param fieldAttrEntity
     */
    public static void initDiscount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.NO.getType());
        fieldAttrEntity.setIntegerOnly(BasicConstant.ZERO);
        fieldAttrEntity.setNumberType(NumberTypeEnum.RATE.getCode());
        NumericalLimitsPoJo numericalLimits = new NumericalLimitsPoJo();
        numericalLimits.setMax(100D);
        numericalLimits.setMin(1D);
        fieldAttrEntity.setNumericalLimits(numericalLimits);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        defaultAttrPoJo.setDefaultValue(BasicConstant.ONE);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    /**
     * 初始化添加回款
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @return void
     * @date 2019/2/20 19:06
     */
    public static void initAddPayment(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.PAYMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initAddPaymentSheet(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
        fieldAttrEntity.setIsOpen(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initAddWriteOffPrepayment(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.WRITE_OFF_PREPAYMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
        fieldAttrEntity.setIsOpen(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 无签订人特殊导入
     *
     * @param fieldAttrEntity
     */
    public static void initSignPerson(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(SIGN_NAME.getAnEnum().getAttr());
        fieldAttrEntity.setIsForbidden(0);
    }



    // public static void initLinkPartnerDistributorHide(FieldAttrEntity fieldAttrEntity) {
    //     fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
    //     fieldAttrEntity.setLinkedText(LINK_PARTNER_DISTRIBUTOR_HIDE.getAnEnum().getAttr());
    //     SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
    //     saasParticularAttributePoJo.setMultiCheck(false);
    //     fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    //     fieldAttrEntity.setIsOpen(BasicConstant.ZERO);
    // }

    public static void initSignTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.setIsForbidden(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.TODAY.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initDeadLine(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initReceivePaymentStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(OrderPayMentStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> paymentStatus = Arrays.asList(OrderPayMentStatusEnum.PENDING_SETTLEMENT.getName(),OrderPayMentStatusEnum.UNCOLLECTED.getName(),OrderPayMentStatusEnum.PARTIAL_RECEIPTS.getName(),OrderPayMentStatusEnum.RECEIPT_FUND.getName());
        for (ItemPoJo itemPoJo : itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!paymentStatus.contains(itemPoJo.getText())){
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            }else if (Objects.equals(itemPoJo.getText(),OrderPayMentStatusEnum.PENDING_SETTLEMENT.getName())){
                itemPoJo.setChecked(true);
            }
        }
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initUnit(FieldAttrEntity fieldAttrEntity) {
        String str = "元,美元,欧元,日元,万,港币,万元";
        List<ItemPoJo> items = InitExplainsHelper.setCombItem(str);
        items.get(0).setChecked(true);
        fieldAttrEntity.setItems(items);
    }

    //订单状态
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
        //不允许被禁用
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setIsDictionary(0);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(OrderStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> orderStatusList = Arrays.asList(OrderStatusEnum.PENDING_ORDER_REVIEW.getName(), OrderStatusEnum.PENDING_FINANCIAL_REVIEW.getName(), OrderStatusEnum.DELIVERED.getName(), OrderStatusEnum.RECEIVED.getName(),
                OrderStatusEnum.COMPLETED.getName(), OrderStatusEnum.CLOSED.getName());
        for (ItemPoJo itemPoJo : itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!orderStatusList.contains(itemPoJo.getText())){
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            }else if (Objects.equals(itemPoJo.getText(),OrderStatusEnum.PENDING_ORDER_REVIEW.getName())){
                itemPoJo.setChecked(true);
            }
        }
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setDictionaryFlag(2);
    }

    //关联产品
    public static void initProducts(FieldAttrEntity fieldAttrEntity){
        //不允许被禁用
        fieldAttrEntity.setIsForbidden(0);
        // 先选经销商才能选产品 暂时用价目表的属性控制了
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setIsOpenPrice(BasicConstant.ONE);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    public static void initType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(OrderTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(2);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setEditable(0);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }

    public static void initMemo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initPayMethod(FieldAttrEntity fieldAttrEntity) {
//        String str = "网银转账,现金,支票,电汇,承兑汇票";
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PayMethodEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    public static void initExpressStatus(FieldAttrEntity fieldAttrEntity) {
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(OrderExpressStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> expressStatusList = Arrays.asList(OrderExpressStatusEnum.DELIVERED.getName(),OrderExpressStatusEnum.PARTIAL_DELIVERY.getName(),OrderExpressStatusEnum.SHIP_ALL.getName());
        for (ItemPoJo itemPoJo : itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!expressStatusList.contains(itemPoJo.getText())){
                itemPoJo.setEditHide(1);
            }else if (Objects.equals(itemPoJo.getText(),ExpressStatusEnum.LACK.getName())){
                itemPoJo.setChecked(true);
            }
        }
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setDictionaryFlag(2);
    }
    public static void initTotalMoney(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setMemo("默认值=产品合计+优惠金额");
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        FormulaPoJo formulaInfo = new FormulaPoJo();
        String formula = "SUM({self." + OrderEnum.PRODUCT_TOTAL.getAttr() + "},{self." + OrderEnum.DISCOUNT_AMOUNT.getAttr() + "})";
        JSONObject labelMap = new JSONObject();
        labelMap.put("self." + OrderEnum.PRODUCT_TOTAL.getAttr(), OrderEnum.PRODUCT_TOTAL.getAttrName());
        labelMap.put("self." + OrderEnum.DISCOUNT_AMOUNT.getAttr(), OrderEnum.DISCOUNT_AMOUNT.getAttrName());
        formulaInfo.setFormula(formula);
        formulaInfo.setLabelMap(labelMap);
        defaultAttrPoJo.setDefaultType("formula");
        defaultAttrPoJo.setFormulaInfo(formulaInfo);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        // 合同金额默认限定 0 ~ 100000000000
        NumericalLimitsPoJo numericalLimits = new NumericalLimitsPoJo();
        numericalLimits.setMin(0D);
        numericalLimits.setMax(100000000000D);
        fieldAttrEntity.setNumericalLimits(numericalLimits);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setShowEditable(0);
    }
    public static void initTotalAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initFinishAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initUnFinishAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initBadAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initUnInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initOrderCost(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setMemo("订单成本= 订单产品总成本 - 退货产品成本 ；其中“订单产品总成本”在实际出库前由预估产品成本计算而得，实际出库之后取实际产品成本计算而得。其中“退货产品成本”会在实际入库之后取实际产品成本计算而得。故而“订单成本”字段会根据实际情况进行变动及更新。(若历史数据不正确，请编辑订货单并保存，系统会自动更正数据)");
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initGrossProfit(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setMemo("订单毛利= 订单金额 - 退货金额 - 订单成本 (若历史数据不正确，请编辑订货单并保存，系统会自动更正数据)");
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initGrossProfitRate(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.AVERAGE.getType());
        fieldAttrEntity.setMemo("订单毛利率 = 订单毛利/订单金额*100%");
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initCashProfit(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setMemo("现金毛利 = 订单已收款金额 - 订单成本");
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initCashProfitRate(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.AVERAGE.getType());
        fieldAttrEntity.setMemo("现金毛利率 = 现金毛利 / 订单已收款金额");
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }
    public static void initArchived(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(ArchivedEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initIsRed(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(IsRedEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initHasRed(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(HasRedEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initShowProduce(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(ContractProduceEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initAllOutBound(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(AllOutBoundEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initIfStatistic(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(IfStatisticEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }
    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initProductTotal(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setMemo("默认值为产品销售价总计");
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        FormulaPoJo formulaInfo = new FormulaPoJo();
        String formula = "SUM({self." + ContractEnum.PRODUCT.getAttr() + "." + SelectProductEnum.SUBTOTAL.getAttr() + "})";
        JSONObject labelMap = new JSONObject();
        labelMap.put("self." + ContractEnum.PRODUCT.getAttr() + "." + SelectProductEnum.SUBTOTAL.getAttr(), "关联产品.售价小计");
        formulaInfo.setFormula(formula);
        formulaInfo.setLabelMap(labelMap);
        defaultAttrPoJo.setDefaultType("formula");
        defaultAttrPoJo.setFormulaInfo(formulaInfo);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        // 合同金额默认限定 0 ~ 100000000000
        NumericalLimitsPoJo numericalLimits = new NumericalLimitsPoJo();
        numericalLimits.setMin(0D);
        numericalLimits.setMax(100000000000D);
        fieldAttrEntity.setNumericalLimits(numericalLimits);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initOtherExpense(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initDiscountAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }


    public static void initLinkContactNumber(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }


    public static void initLinkShippingAddress(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }


    public static void initShipStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(ShipStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> shipStatusCodeList = Arrays.asList(ShipStatusEnum.UNSHIPPED.getName(),ShipStatusEnum.DELIVERED.getName(),ShipStatusEnum.SHIPPED.getName(),ShipStatusEnum.CLOSED.getName());
        for (ItemPoJo itemPoJo: itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!shipStatusCodeList.contains(itemPoJo.getText())) {
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            } else {
                if (Objects.equals(itemPoJo.getText(), ShipStatusEnum.UNSHIPPED.getName())) {
                    itemPoJo.setChecked(true);
                }
            }
        }
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    /**
     * 初始化应收账期
     */
    public static void initReceivablePeriod(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsOpen(BasicConstant.ZERO);
        fieldAttrEntity.setNoRepeat(BasicConstant.ZERO);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setMemo(I18nMessageUtil.getMessage(I18nStringConstant.RECEIVABLE_PERIOD));
    }

    /**
     * 初始化已出库优惠金额
     *
     * @param fieldAttrEntity 表单字段属性类
     */
    public static void initOutstockDiscountAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
    }
}
